import homeApi from '@/api/homeApi'
import { AxiosResponse } from 'axios'
import UseSearchForm from '@/hooks/useSearchFormHooks'
const { useSearchForm } = UseSearchForm
const { isLoading, isFinished, examList } = useSearchForm

export interface Exam {
  age: string
  describes: string
  diagnosis: string
  fromDeptName: string
  fromDocName: string
  id: string
  inPatientNo: string
  isFinished: string
  machineName: string
  machineType: string
  moduleName: string
  name: string
  oldDocID: string
  outPatientNo: string
  reportDate: string
  reportTime: string
  sex: string
  sickBedNo: string
  visceras: string
}

export interface FindExamList {
  rows: Exam[]
}

class HomeService {
  static homeService = new HomeService()
  async handleOnloadData() {
    console.log(isFinished.value)
    if (isFinished.value) {
      return
    }
    if (examList.value?.length) {
      isLoading.value = true
      UseSearchForm.page += 1
      const res: AxiosResponse<FindExamList> = await homeApi.findExamList(
        UseSearchForm.page,
        UseSearchForm.size,
        UseSearchForm.form
      )
      UseSearchForm.useSearchForm.isLoading.value = false
      if (res.data.rows.length === 0) {
        isFinished.value = true
        return
      }
      examList.value?.push(...res.data.rows)
    }
  }
}

export default HomeService.homeService
